package com.cyz.web.app.concurrent;

import lombok.AllArgsConstructor;

public class MultiThreadLong {

    public  static  long i = 0;

    @AllArgsConstructor
    public static class ChangeT implements Runnable {
        private long to;

        @Override
        public void run() {
            while (true) {
                MultiThreadLong.i = to;
                Thread.yield();
            }
        }
    }


    public static class ReadT implements Runnable {

        @Override
        public void run() {
            while (true) {
                long temp = MultiThreadLong.i;
//                if (temp != 111L && temp != -999L && temp != 333L && temp != -444L) {
                    System.out.println(temp);
//                }
                Thread.yield();
            }
        }
    }


    public static void main(String[] args) {
        new Thread(new ChangeT(111L)).start();
        new Thread(new ChangeT(-999L)).start();
        new Thread(new ChangeT(333L)).start();
        new Thread(new ChangeT(-444L)).start();
        new Thread(new ReadT()).start();
    }

}
